
include("cenf.jl")
cenf.readData(root)

using JLD
using Gadfly

println("Welfare counterfactual for Z_F (fixed theta)")

f=load("$(root)/output/ms_ces_f_output_rhothetafixed.jld");
ms_fvals = f["ms_fvals"];
ms_β = f["ms_β"];
ms_η = f["ms_η"];
ms_γ = f["ms_γ"];
ms_logT = f["ms_logT"];
ms_logS = f["ms_logS"];

idx_best = findfirst(isequal(maximum(ms_fvals)), vec(ms_fvals));

bestβ = vec(ms_β[idx_best,:])
bestη = vec(ms_η[idx_best,:])
bestγ = reshape(ms_γ[idx_best,:],35,35);
bestlogT = reshape(ms_logT[idx_best,:],109,35);
bestlogS = reshape(ms_logS[idx_best,:],109,35);

include("cenf.jl")
cenf.readData(root)

(changeArray_FF_CES,ioshares_before_FF_CES,ioshares_after_FF_CES) = cenf.solveCountries_ces(4.0, 4.0, bestβ, bestη, bestγ, 2.0, exp.(bestlogT), exp.(bestlogS),"../output/welfare_us_ces_f","z^(2) used")
